package org.datastealer.service.impl;

import org.datastealer.bean.Column;
import org.datastealer.bean.Table;
import org.datastealer.dao.api.TableDao;
import org.datastealer.service.TableService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * Note：
 *
 * @author ：mengjw
 * @description：数据库表服务实现
 * @date ：Created in 2020/8/22
 */
@Service
public class TableServiceImpl implements TableService {

    @Lazy
    @Autowired
    private TableDao tableDao;

    @Override
    public List<Table> getTablesBySchema(String schemaName) {
        return tableDao.getTablesBySchema(schemaName);
    }

    @Override
    public String getTableDDL(String schemaName, String tableName) {
        return tableDao.getTableDDL(schemaName, tableName);
    }

    @Override
    public List<Column> getTableColumns(String schemaName, String tableName) {
        return tableDao.getTableColumns(schemaName, tableName);
    }

    @Override
    public List<Map<String, Object>> getDataByPage(String schemaName, String tableName, Integer pageNum, Integer pageSize) {
        int startRow = pageNum > 0 ? (pageNum - 1) * pageSize : 0;
        int endRow = startRow + pageSize * (pageNum > 0 ? 1 : 0);
        return tableDao.getDataByPage(schemaName, tableName, startRow, endRow);
    }

}